/**
 * 
 */
package com.ws.framework.controller;

import org.apache.shiro.SecurityUtils;

import com.ws.framework.model.User;

/**
 * <p>
 * </p>
 *
 * @author WSH
 */
public class BaseController {

	/**
	 * 获取登录用户信息
	 * @return
	 */
	public User getUserEntity() {
		return (User)SecurityUtils.getSubject().getPrincipal();
	}
	
	/**
	 * 成功,返回状态
	 * @return
	 */
	public ResultJsonBean success() {
		return new ResultJsonBean();
	}
	
	/**
	 * 成功，返回json数据
	 * @param data
	 * @return
	 */
	public ResultJsonBean success(Object data) {
		ResultJsonBean bean = new ResultJsonBean();
		bean.setData(data);
		return bean;
	}
	
	/**
	 * 失败,返回状态及原因
	 * @param result
	 * @return
	 */
	public ResultJsonBean fail(EnumSvrResult result) {
		ResultJsonBean bean = new ResultJsonBean();
		bean.setMessage(result.getName());
		bean.setStatus(result.getVal());
		return bean;
	}
	
	/**
	 * 失败,返回状态及原因
	 * @param message
	 * @param status
	 * @return
	 */
	public ResultJsonBean fail(String message,String status) {
		ResultJsonBean bean = new ResultJsonBean();
		bean.setMessage(message);
		bean.setStatus(status);
		return bean;
	}
	
	/**
	 * 服务器异常
	 * @return
	 */
	public ResultJsonBean error() {
		ResultJsonBean bean = new ResultJsonBean();
		bean.setMessage(EnumSvrResult.ERROR.getName());
		bean.setStatus(EnumSvrResult.ERROR.getVal());
		return bean;
	}
    
}
